﻿@{
    ViewBag.Title = "主页";
}
@if (false)
{
    <script type="text/javascript" src="../../Scripts/jquery-1.4.4-vsdoc.js"></script>
}
<table width="100%">
    <tr>
        <td width="23%" style="vertical-align:top;table-layout:fixed;word-break:break-all;word-wrap:break-word;">
            <div><a href="javascript:void(0);" onclick="ExportCore();">生成</a></div>
            <div>@Html.Action("TableTree", "PDM")</div>
        </td>
        <td width="77%" style="vertical-align:top;table-layout:fixed;word-break:break-all;word-wrap:break-word;">
            <div id="div_CoreTemplate">
                表:<span id="span_TableInfo"></span><br />
                <input type="radio" name="CoreTemplate" onclick="LoadCoreTemplate('BaseModel');" checked="checked" id="rad_BaseModel" /><label for="rad_BaseModel">BaseModel</label>
                <input type="radio" name="CoreTemplate" onclick="LoadCoreTemplate('Model');" id="rad_Model" /><label for="rad_Model">Model</label>
                <input type="radio" name="CoreTemplate" onclick="LoadCoreTemplate('IDAL');" id="rad_IDAL" /><label for="rad_IDAL">IDAL</label>
                <input type="radio" name="CoreTemplate" onclick="LoadCoreTemplate('BaseDAL');" id="rad_BaseDAL" /><label for="rad_BaseDAL">BaseDAL</label>
                <input type="radio" name="CoreTemplate" onclick="LoadCoreTemplate('DAL');" id="rad_DAL" /><label for="rad_DAL">DAL</label>
                <div id="div_Core_CSharp"></div>
            </div>
        </td>
    </tr>
</table>
<script type="text/javascript">
    
    var selectTableName = null;
    var selectTBDescription = null;
    //重写PDM/TableTree事件.
    function OnPDMTableSelect(tableName, description) {
        LoadTable(tableName, description);
    }

    function LoadTable(tableName, description) {
        selectTableName = tableName;
        selectTBDescription = description;
        $("#span_TableInfo").html(description);
        var CoreTemplate = "BaseModel";
        $("#rad_BaseModel").attr("checked",true);
        LoadCoreTemplate(CoreTemplate);
    }

    function LoadCoreTemplate(CoreTemplate) {
        var url = "@Url.Action("CoreAction", "CoreTemplate")" ;
        var data = { 'TableName': selectTableName,'BuildType':CoreTemplate };
        $.ajax({
            type: "post",
            url: url,
            dataType: "text",
            data: data,
            success: function (msg) {
                $("#div_Core_CSharp").html("<textarea name=\"Core_CSharp\" class=\"C#\">"+msg+"</textarea>");
                dp.SyntaxHighlighter.HighlightAll("Core_CSharp");
                $("#div_CoreTemplate").show();
            },
            failure: function () {
                alert("Ajax错误");
            }
        });
    }

    $(function () {
        if (selectTableName == null) {
            $("#div_CoreTemplate").hide();
        } else {
            LoadTable(selectTableName, selectTBDescription);
        }
    })

    //生成
    function ExportCore() {
        var tables = GetPDMSelectTables();
        var s_tables = tables.join(",");
        var url = "@Url.Action("Create", "CoreTemplate")" + "?tables="+s_tables;
        $.ajax({
            type: "post",
            url: url,
            success:function(msg){
                if(msg!=null){
                    alert(msg);
                }
            }
        });
    }

</script>

<link type="text/css" rel="stylesheet" href="@Url.Content("~/SyntaxHighlighter/Styles/SyntaxHighlighter.css")" />
<script type="text/javascript" src="@Url.Content("~/SyntaxHighlighter/Scripts/shCore.js")"></script>
<script type="text/javascript" src="@Url.Content("~/SyntaxHighlighter/Scripts/shBrushCSharp.js")"></script>
<script type="text/javascript">
    var CurrentMenu = "代码";
</script>